home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Games / ADoom / ADoom_src / am_map.c < prev    next >
C/C++ Source or Header  |  1998-01-26  |  33KB  |  1,451 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:  the automap code
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24. static const char rcsid[] = "$Id: am_map.c,v 1.4 1997/02/03 21:24:33 b1 Exp $";
  25.  
  26. #include <stdio.h>
  27.  
  28.  
  29. #include "z_zone.h"
  30. #include "doomdef.h"
  31. #include "st_stuff.h"
  32. #include "p_local.h"
  33. #include "w_wad.h"
  34.  
  35. #include "m_cheat.h"
  36. #include "i_system.h"
  37.  
  38. // Needs access to LFB.
  39. #include "v_video.h"
  40.  
  41. // State.
  42. #include "doomstat.h"
  43. #include "r_state.h"
  44.  
  45. // Data.
  46. #include "dstrings.h"
  47.  
  48. #include "am_map.h"
  49.  
  50.  
  51. // For use if I do walls with outsides/insides
  52. #define REDS            (256-5*16)
  53. #define REDRANGE        16
  54. #define BLUES           (256-4*16+8)
  55. #define BLUERANGE       8
  56. #define GREENS          (7*16)
  57. #define GREENRANGE      16
  58. #define GRAYS           (6*16)
  59. #define GRAYSRANGE      16
  60. #define BROWNS          (4*16)
  61. #define BROWNRANGE      16
  62. #define YELLOWS         (256-32+7)
  63. #define YELLOWRANGE     1
  64. #define BLACK           0
  65. #define WHITE           (256-47)
  66.  
  67. // Automap colors
  68. #define BACKGROUND      BLACK
  69. #define YOURCOLORS      WHITE
  70. #define YOURRANGE       0
  71. #define WALLCOLORS      REDS
  72. #define WALLRANGE       REDRANGE
  73. #define TSWALLCOLORS    GRAYS
  74. #define TSWALLRANGE     GRAYSRANGE
  75. #define FDWALLCOLORS    BROWNS
  76. #define FDWALLRANGE     BROWNRANGE
  77. #define CDWALLCOLORS    YELLOWS
  78. #define CDWALLRANGE     YELLOWRANGE
  79. #define THINGCOLORS     GREENS
  80. #define THINGRANGE      GREENRANGE
  81. #define SECRETWALLCOLORS WALLCOLORS
  82. #define SECRETWALLRANGE WALLRANGE
  83. #define GRIDCOLORS      (GRAYS + GRAYSRANGE/2)
  84. #define GRIDRANGE       0
  85. #define XHAIRCOLORS     GRAYS
  86.  
  87. // drawing stuff
  88. #define FB              0
  89.  
  90. #define AM_PANDOWNKEY   KEY_DOWNARROW
  91. #define AM_PANUPKEY     KEY_UPARROW
  92. #define AM_PANRIGHTKEY  KEY_RIGHTARROW
  93. #define AM_PANLEFTKEY   KEY_LEFTARROW
  94. #define AM_ZOOMINKEY    '='
  95. #define AM_ZOOMOUTKEY   '-'
  96. #define AM_STARTKEY     KEY_TAB
  97. #define AM_ENDKEY       KEY_TAB
  98. #define AM_GOBIGKEY     '0'
  99. #define AM_FOLLOWKEY    'f'
  100. #define AM_GRIDKEY      'g'
  101. #define AM_MARKKEY      'm'
  102. #define AM_CLEARMARKKEY 'c'
  103.  
  104. #define AM_NUMMARKPOINTS 10
  105.  
  106. // scale on entry
  107. #define INITSCALEMTOF (.2*FRACUNIT)
  108. // how much the automap moves window per tic in frame-buffer coordinates
  109. // moves 140 pixels in 1 second
  110. #define F_PANINC        4
  111. // how much zoom-in per tic
  112. // goes to 2x in 1 second
  113. #define M_ZOOMIN        ((int) (1.02*FRACUNIT))
  114. // how much zoom-out per tic
  115. // pulls out to 0.5x in 1 second
  116. #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))
  117.  
  118. // translates between frame-buffer and map distances
  119. #define FTOM(x) FixedMul(((x)<<16),scale_ftom)
  120. #define MTOF(x) (FixedMul((x),scale_mtof)>>16)
  121. // translates between frame-buffer and map coordinates
  122. #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
  123. #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
  124.  
  125. // the following is crap
  126. #define LINE_NEVERSEE ML_DONTDRAW
  127.  
  128. typedef struct
  129. {
  130.     int x, y;
  131. } fpoint_t;
  132.  
  133. typedef struct
  134. {
  135.     fpoint_t a, b;
  136. } fline_t;
  137.  
  138. typedef struct
  139. {
  140.     fixed_t             x,y;
  141. } mpoint_t;
  142.  
  143. typedef struct
  144. {
  145.     mpoint_t a, b;
  146. } mline_t;
  147.  
  148. typedef struct
  149. {
  150.     fixed_t slp, islp;
  151. } islope_t;
  152.  
  153.  
  154.  
  155. //
  156. // The vector graphics for the automap.
  157. //  A line drawing of the player pointing right,
  158. //   starting from the middle.
  159. //
  160. #define R ((8*PLAYERRADIUS)/7)
  161. mline_t player_arrow[] = {
  162.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  163.     { { R, 0 }, { R-R/2, R/4 } },  // ----->
  164.     { { R, 0 }, { R-R/2, -R/4 } },
  165.     { { -R+R/8, 0 }, { -R-R/8, R/4 } }, // >---->
  166.     { { -R+R/8, 0 }, { -R-R/8, -R/4 } },
  167.     { { -R+3*R/8, 0 }, { -R+R/8, R/4 } }, // >>--->
  168.     { { -R+3*R/8, 0 }, { -R+R/8, -R/4 } }
  169. };
  170. #undef R
  171. #define NUMPLYRLINES (sizeof(player_arrow)/sizeof(mline_t))
  172.  
  173. #define R ((8*PLAYERRADIUS)/7)
  174. mline_t cheat_player_arrow[] = {
  175.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  176.     { { R, 0 }, { R-R/2, R/6 } },  // ----->
  177.     { { R, 0 }, { R-R/2, -R/6 } },
  178.     { { -R+R/8, 0 }, { -R-R/8, R/6 } }, // >----->
  179.     { { -R+R/8, 0 }, { -R-R/8, -R/6 } },
  180.     { { -R+3*R/8, 0 }, { -R+R/8, R/6 } }, // >>----->
  181.     { { -R+3*R/8, 0 }, { -R+R/8, -R/6 } },
  182.     { { -R/2, 0 }, { -R/2, -R/6 } }, // >>-d--->
  183.     { { -R/2, -R/6 }, { -R/2+R/6, -R/6 } },
  184.     { { -R/2+R/6, -R/6 }, { -R/2+R/6, R/4 } },
  185.     { { -R/6, 0 }, { -R/6, -R/6 } }, // >>-dd-->
  186.     { { -R/6, -R/6 }, { 0, -R/6 } },
  187.     { { 0, -R/6 }, { 0, R/4 } },
  188.     { { R/6, R/4 }, { R/6, -R/7 } }, // >>-ddt->
  189.     { { R/6, -R/7 }, { R/6+R/32, -R/7-R/32 } },
  190.     { { R/6+R/32, -R/7-R/32 }, { R/6+R/10, -R/7 } }
  191. };
  192. #undef R
  193. #define NUMCHEATPLYRLINES (sizeof(cheat_player_arrow)/sizeof(mline_t))
  194.  
  195. #define R (FRACUNIT)
  196. mline_t triangle_guy[] = {
  197.     { { -.867*R, -.5*R }, { .867*R, -.5*R } },
  198.     { { .867*R, -.5*R } , { 0, R } },
  199.     { { 0, R }, { -.867*R, -.5*R } }
  200. };
  201. #undef R
  202. #define NUMTRIANGLEGUYLINES (sizeof(triangle_guy)/sizeof(mline_t))
  203.  
  204. #define R (FRACUNIT)
  205. mline_t thintriangle_guy[] = {
  206.     { { -.5*R, -.7*R }, { R, 0 } },
  207.     { { R, 0 }, { -.5*R, .7*R } },
  208.     { { -.5*R, .7*R }, { -.5*R, -.7*R } }
  209. };
  210. #undef R
  211. #define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
  212.  
  213.  
  214.  
  215.  
  216. static int      cheating = 0;
  217. static int      grid = 0;
  218.  
  219. static int      leveljuststarted = 1;   // kluge until AM_LevelInit() is called
  220.  
  221. boolean         automapactive = false;
  222.  
  223. static int      finit_width = SCREENWIDTH;
  224. static int      finit_height = SCREENHEIGHT - 32;
  225.  
  226. extern int      viewwidth; /* CDE'98 - Need this for maponhu */
  227. extern int      viewheight; /* CDE'98 - Need this for maponhu */
  228. extern int      viewwindowx; /* CDE'98 - Need this for maponhu */
  229. extern int      viewwindowy; /* CDE'98 - Need this for maponhu */
  230.  
  231. int      wx; /* CDE'98 - x offset from view */
  232. int      wy; /* CDE'98 - y offset from view */
  233.  
  234. // location of window on screen
  235. static int      f_x;
  236. static int      f_y;
  237.  
  238. // size of window on screen
  239. static int      f_w;
  240. static int      f_h;
  241.  
  242. static int      lightlev;               // used for funky strobing effect
  243. static byte*    fb;                     // pseudo-frame buffer
  244. static int      amclock;
  245.  
  246. static mpoint_t m_paninc; // how far the window pans each tic (map coords)
  247. static fixed_t  mtof_zoommul; // how far the window zooms in each tic (map coords)
  248. static fixed_t  ftom_zoommul; // how far the window zooms in each tic (fb coords)
  249.  
  250. static fixed_t  m_x, m_y;   // LL x,y where the window is on the map (map coords)
  251. static fixed_t  m_x2, m_y2; // UR x,y where the window is on the map (map coords)
  252.  
  253. //
  254. // width/height of window on map (map coords)
  255. //
  256. static fixed_t  m_w;
  257. static fixed_t  m_h;
  258.  
  259. // based on level size
  260. static fixed_t  min_x;
  261. static fixed_t  min_y; 
  262. static fixed_t  max_x;
  263. static fixed_t  max_y;
  264.  
  265. static fixed_t  max_w; // max_x-min_x,
  266. static fixed_t  max_h; // max_y-min_y
  267.  
  268. // based on player size
  269. static fixed_t  min_w;
  270. static fixed_t  min_h;
  271.  
  272.  
  273. static fixed_t  min_scale_mtof; // used to tell when to stop zooming out
  274. static fixed_t  max_scale_mtof; // used to tell when to stop zooming in
  275.  
  276. // old stuff for recovery later
  277. static fixed_t old_m_w, old_m_h;
  278. static fixed_t old_m_x, old_m_y;
  279.  
  280. // old location used by the Follower routine
  281. static mpoint_t f_oldloc;
  282.  
  283. // used by MTOF to scale from map-to-frame-buffer coords
  284. static fixed_t scale_mtof = INITSCALEMTOF;
  285. // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
  286. static fixed_t scale_ftom;
  287.  
  288. static player_t *plr; // the player represented by an arrow
  289.  
  290. static patch_t *marknums[10]; // numbers used for marking by the automap
  291. static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
  292. static int markpointnum = 0; // next point to be assigned
  293.  
  294. static int followplayer = 1; // specifies whether to follow the player around
  295.  
  296. static unsigned char cheat_amap_seq[] = { 0xb2, 0x26, 0x26, 0x2e, 0xff };
  297. static cheatseq_t cheat_amap = { cheat_amap_seq, 0 };
  298.  
  299. static boolean stopped = true;
  300.  
  301. extern boolean viewactive;
  302. extern boolean rotatemap;
  303. extern boolean maponhu;
  304. //extern byte screens[][SCREENWIDTH*SCREENHEIGHT];
  305.  
  306.  
  307.  
  308. void
  309. V_MarkRect
  310. ( int   x,
  311.   int   y,
  312.   int   width,
  313.   int   height );
  314.  
  315. //
  316. // Rotation in 2D.
  317. // Used to rotate player arrow line character.
  318. //
  319. void
  320. AM_rotate
  321. ( fixed_t*      x,
  322.   fixed_t*      y,
  323.   angle_t       a )
  324. {
  325.     fixed_t tmpx;
  326.  
  327.     tmpx =
  328.         FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
  329.         - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
  330.     
  331.     *y   =
  332.         FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
  333.         + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
  334.  
  335.     *x = tmpx;
  336. }
  337.  
  338. // Calculates the slope and slope according to the x-axis of a line
  339. // segment in map coordinates (with the upright y-axis n' all) so
  340. // that it can be used with the brain-dead drawing stuff.
  341.  
  342. void
  343. AM_getIslope
  344. ( mline_t*      ml,
  345.   islope_t*     is )
  346. {
  347.     int dx, dy;
  348.  
  349.     dy = ml->a.y - ml->b.y;
  350.     dx = ml->b.x - ml->a.x;
  351.     if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
  352.     else is->islp = FixedDiv(dx, dy);
  353.     if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
  354.     else is->slp = FixedDiv(dy, dx);
  355.  
  356. }
  357.  
  358. //
  359. //
  360. //
  361. void AM_activateNewScale(void)
  362. {
  363.     m_x += m_w/2;
  364.     m_y += m_h/2;
  365.     m_w = FTOM(f_w);
  366.     m_h = FTOM(f_h);
  367.     m_x -= m_w/2;
  368.     m_y -= m_h/2;
  369.     m_x2 = m_x + m_w;
  370.     m_y2 = m_y + m_h;
  371. }
  372.  
  373. //
  374. //
  375. //
  376. void AM_saveScaleAndLoc(void)
  377. {
  378.     old_m_x = m_x;
  379.     old_m_y = m_y;
  380.     old_m_w = m_w;
  381.     old_m_h = m_h;
  382. }
  383.  
  384. //
  385. //
  386. //
  387. void AM_restoreScaleAndLoc(void)
  388. {
  389.  
  390.     m_w = old_m_w;
  391.     m_h = old_m_h;
  392.     if (!followplayer)
  393.     {
  394.         m_x = old_m_x;
  395.         m_y = old_m_y;
  396.     } else {
  397.         m_x = plr->mo->x - m_w/2;
  398.         m_y = plr->mo->y - m_h/2;
  399.     }
  400.     m_x2 = m_x + m_w;
  401.     m_y2 = m_y + m_h;
  402.  
  403.     // Change the scaling multipliers
  404.     scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
  405.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  406. }
  407.  
  408. //
  409. // adds a marker at the current location
  410. //
  411. void AM_addMark(void)
  412. {
  413.     markpoints[markpointnum].x = m_x + m_w/2;
  414.     markpoints[markpointnum].y = m_y + m_h/2;
  415.     markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
  416.  
  417. }
  418.  
  419. //
  420. // Determines bounding box of all vertices,
  421. // sets global variables controlling zoom range.
  422. //
  423. void AM_findMinMaxBoundaries(void)
  424. {
  425.     int i;
  426.     fixed_t a;
  427.     fixed_t b;
  428.  
  429.     min_x = min_y =  MAXINT;
  430.     max_x = max_y = -MAXINT;
  431.   
  432.     for (i=0;i<numvertexes;i++)
  433.     {
  434.         if (vertexes[i].x < min_x)
  435.             min_x = vertexes[i].x;
  436.         else if (vertexes[i].x > max_x)
  437.             max_x = vertexes[i].x;
  438.     
  439.         if (vertexes[i].y < min_y)
  440.             min_y = vertexes[i].y;
  441.         else if (vertexes[i].y > max_y)
  442.             max_y = vertexes[i].y;
  443.     }
  444.   
  445.     max_w = max_x - min_x;
  446.     max_h = max_y - min_y;
  447.  
  448.     min_w = 2*PLAYERRADIUS; // const? never changed?
  449.     min_h = 2*PLAYERRADIUS;
  450.  
  451.     a = FixedDiv(f_w<<FRACBITS, max_w);
  452.     b = FixedDiv(f_h<<FRACBITS, max_h);
  453.   
  454.     min_scale_mtof = a < b ? a : b;
  455.     max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
  456.  
  457. }
  458.  
  459.  
  460. //
  461. //
  462. //
  463. void AM_changeWindowLoc(void)
  464. {
  465.     if (m_paninc.x || m_paninc.y)
  466.     {
  467.         followplayer = 0;
  468.         f_oldloc.x = MAXINT;
  469.     }
  470.  
  471.     /* CDE'98 Rotate Map Patch - Rotate paninc or not ?? make your choice ... */
  472. /*
  473.     if(rotatemap)
  474.     {
  475.         fixed_t x,y;
  476.         x=m_paninc.x;
  477.         y=m_paninc.y;
  478.         AM_rotate(&x, &y, ANG90-plr->mo->angle);
  479.         m_x += x;
  480.         m_y += y;
  481.     } else {
  482. */
  483.         m_x += m_paninc.x;
  484.         m_y += m_paninc.y;
  485. /*
  486.     }
  487. */
  488.  
  489.     /* CDE'98  - checking for limit is disabled while in rotate mode */
  490.     /*           should not cause any problem */
  491.     if(!rotatemap)
  492.     {
  493.         if (m_x + m_w/2 > max_x)
  494.             m_x = max_x - m_w/2;
  495.         else if (m_x + m_w/2 < min_x)
  496.             m_x = min_x - m_w/2;
  497.   
  498.         if (m_y + m_h/2 > max_y)
  499.             m_y = max_y - m_h/2;
  500.         else if (m_y + m_h/2 < min_y)
  501.             m_y = min_y - m_h/2;
  502.     }
  503.  
  504.     m_x2 = m_x + m_w;
  505.     m_y2 = m_y + m_h;
  506. }
  507.  
  508.  
  509. //
  510. //
  511. //
  512. void AM_initVariables(void)
  513. {
  514.     int pnum;
  515.     static event_t st_notify = { ev_keyup, AM_MSGENTERED };
  516.  
  517.     automapactive = true;
  518.     fb = screens[0];
  519.  
  520.     f_oldloc.x = MAXINT;
  521.     amclock = 0;
  522.     lightlev = 0;
  523.  
  524.     m_paninc.x = m_paninc.y = 0;
  525.     ftom_zoommul = FRACUNIT;
  526.     mtof_zoommul = FRACUNIT;
  527.  
  528.     /* CDE'98 - Calculate view position and size */
  529.     if(maponhu)
  530.     {
  531.         wx = viewwindowx;
  532.         wy = viewwindowy;
  533.         f_w = viewwidth;
  534.         f_h = viewheight;
  535.     } else {
  536.         wx = 0;
  537.         wy = 0;
  538.         f_w = finit_width;
  539.         f_h = finit_height;
  540.     }
  541.  
  542.     m_w = FTOM(f_w);
  543.     m_h = FTOM(f_h);
  544.  
  545.     // find player to center on initially
  546.     if (!playeringame[pnum = consoleplayer])
  547.         for (pnum=0;pnum<MAXPLAYERS;pnum++)
  548.             if (playeringame[pnum])
  549.                 break;
  550.   
  551.     plr = &players[pnum];
  552.     m_x = plr->mo->x - m_w/2;
  553.     m_y = plr->mo->y - m_h/2;
  554.     AM_changeWindowLoc();
  555.  
  556.     // for saving & restoring
  557.     old_m_x = m_x;
  558.     old_m_y = m_y;
  559.     old_m_w = m_w;
  560.     old_m_h = m_h;
  561.  
  562.     // inform the status bar of the change
  563.     ST_Responder(&st_notify);
  564.  
  565. }
  566.  
  567. //
  568. // 
  569. //
  570. void AM_loadPics(void)
  571. {
  572.     int i;
  573.     char namebuf[9];
  574.   
  575.     for (i=0;i<10;i++)
  576.     {
  577.         sprintf(namebuf, "AMMNUM%d", i);
  578.         marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
  579.     }
  580.  
  581. }
  582.  
  583. void AM_unloadPics(void)
  584. {
  585.     int i;
  586.   
  587.     for (i=0;i<10;i++)
  588.         Z_ChangeTag(marknums[i], PU_CACHE);
  589.  
  590. }
  591.  
  592. void AM_clearMarks(void)
  593. {
  594.     int i;
  595.  
  596.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  597.         markpoints[i].x = -1; // means empty
  598.     markpointnum = 0;
  599. }
  600.  
  601. //
  602. // should be called at the start of every level
  603. // right now, i figure it out myself
  604. //
  605. void AM_LevelInit(void)
  606. {
  607.     leveljuststarted = 0;
  608.  
  609.     f_x = f_y = 0;
  610.  
  611.     /* CDE'98 - Calculate view position and size */
  612.     if(maponhu)
  613.     {
  614.         wx = viewwindowx;
  615.         wy = viewwindowy;
  616.         f_w = viewwidth;
  617.         f_h = viewheight;
  618.     } else {
  619.         wx = 0;
  620.         wy = 0;
  621.         f_w = finit_width;
  622.         f_h = finit_height;
  623.     }
  624.  
  625.     AM_clearMarks();
  626.  
  627.     AM_findMinMaxBoundaries();
  628.     scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
  629.     if (scale_mtof > max_scale_mtof)
  630.         scale_mtof = min_scale_mtof;
  631.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  632. }
  633.  
  634.  
  635.  
  636.  
  637. //
  638. //
  639. //
  640. void AM_Stop (void)
  641. {
  642.     static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
  643.  
  644.     AM_unloadPics();
  645.     automapactive = false;
  646.     ST_Responder(&st_notify);
  647.     stopped = true;
  648. }
  649.  
  650. //
  651. //
  652. //
  653. void AM_Start (void)
  654. {
  655.     static int lastlevel = -1, lastepisode = -1;
  656.  
  657.     if (!stopped) AM_Stop();
  658.     stopped = false;
  659.     if (lastlevel != gamemap || lastepisode != gameepisode)
  660.     {
  661.         AM_LevelInit();
  662.         lastlevel = gamemap;
  663.         lastepisode = gameepisode;
  664.     }
  665.     AM_initVariables();
  666.     AM_loadPics();
  667. }
  668.  
  669. //
  670. // set the window scale to the maximum size
  671. //
  672. void AM_minOutWindowScale(void)
  673. {
  674.     scale_mtof = min_scale_mtof;
  675.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  676.     AM_activateNewScale();
  677. }
  678.  
  679. //
  680. // set the window scale to the minimum size
  681. //
  682. void AM_maxOutWindowScale(void)
  683. {
  684.     scale_mtof = max_scale_mtof;
  685.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  686.     AM_activateNewScale();
  687. }
  688.  
  689.  
  690. //
  691. // Handle events (user inputs) in automap mode
  692. //
  693. boolean
  694. AM_Responder
  695. ( event_t*      ev )
  696. {
  697.  
  698.     int rc;
  699.     static int cheatstate=0;
  700.     static int bigstate=0;
  701.     static char buffer[20];
  702.  
  703.     rc = false;
  704.  
  705.     if (!automapactive)
  706.     {
  707.         if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY)
  708.         {
  709.             AM_Start ();
  710.             /* CDE'98 Map on Headup Patch */
  711.             if(!maponhu)
  712.                 viewactive = false;
  713.             rc = true;
  714.         }
  715.     }
  716.  
  717.     else if (ev->type == ev_keydown)
  718.     {
  719.  
  720.         rc = true;
  721.         switch(ev->data1)
  722.         {
  723.           case AM_PANRIGHTKEY: // pan right
  724.             if (!followplayer) m_paninc.x = FTOM(F_PANINC);
  725.             else rc = false;
  726.             break;
  727.           case AM_PANLEFTKEY: // pan left
  728.             if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
  729.             else rc = false;
  730.             break;
  731.           case AM_PANUPKEY: // pan up
  732.             if (!followplayer) m_paninc.y = FTOM(F_PANINC);
  733.             else rc = false;
  734.             break;
  735.           case AM_PANDOWNKEY: // pan down
  736.             if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
  737.             else rc = false;
  738.             break;
  739.           case AM_ZOOMOUTKEY: // zoom out
  740.             mtof_zoommul = M_ZOOMOUT;
  741.             ftom_zoommul = M_ZOOMIN;
  742.             break;
  743.           case AM_ZOOMINKEY: // zoom in
  744.             mtof_zoommul = M_ZOOMIN;
  745.             ftom_zoommul = M_ZOOMOUT;
  746.             break;
  747.           case AM_ENDKEY:
  748.             bigstate = 0;
  749.             viewactive = true;
  750.             AM_Stop ();
  751.             break;
  752.           case AM_GOBIGKEY:
  753.             bigstate = !bigstate;
  754.             if (bigstate)
  755.             {
  756.                 AM_saveScaleAndLoc();
  757.                 AM_minOutWindowScale();
  758.             }
  759.             else AM_restoreScaleAndLoc();
  760.             break;
  761.           case AM_FOLLOWKEY:
  762.             followplayer = !followplayer;
  763.             f_oldloc.x = MAXINT;
  764.             plr->message = followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF;
  765.             break;
  766.           case AM_GRIDKEY:
  767.             grid = !grid;
  768.             plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
  769.             break;
  770.           case AM_MARKKEY:
  771.             sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
  772.             plr->message = buffer;
  773.             AM_addMark();
  774.             break;
  775.           case AM_CLEARMARKKEY:
  776.             AM_clearMarks();
  777.             plr->message = AMSTR_MARKSCLEARED;
  778.             break;
  779.           default:
  780.             cheatstate=0;
  781.             rc = false;
  782.         }
  783.         if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
  784.         {
  785.             rc = false;
  786.             cheating = (cheating+1) % 3;
  787.         }
  788.     }
  789.  
  790.     else if (ev->type == ev_keyup)
  791.     {
  792.         rc = false;
  793.         switch (ev->data1)
  794.         {
  795.           case AM_PANRIGHTKEY:
  796.             if (!followplayer) m_paninc.x = 0;
  797.             break;
  798.           case AM_PANLEFTKEY:
  799.             if (!followplayer) m_paninc.x = 0;
  800.             break;
  801.           case AM_PANUPKEY:
  802.             if (!followplayer) m_paninc.y = 0;
  803.             break;
  804.           case AM_PANDOWNKEY:
  805.             if (!followplayer) m_paninc.y = 0;
  806.             break;
  807.           case AM_ZOOMOUTKEY:
  808.           case AM_ZOOMINKEY:
  809.             mtof_zoommul = FRACUNIT;
  810.             ftom_zoommul = FRACUNIT;
  811.             break;
  812.         }
  813.     }
  814.  
  815.     return rc;
  816.  
  817. }
  818.  
  819.  
  820. //
  821. // Zooming
  822. //
  823. void AM_changeWindowScale(void)
  824. {
  825.  
  826.     // Change the scaling multipliers
  827.     scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
  828.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  829.  
  830.     if (scale_mtof < min_scale_mtof)
  831.         AM_minOutWindowScale();
  832.     else if (scale_mtof > max_scale_mtof)
  833.         AM_maxOutWindowScale();
  834.     else
  835.         AM_activateNewScale();
  836. }
  837.  
  838.  
  839. //
  840. //
  841. //
  842. void AM_doFollowPlayer(void)
  843. {
  844.  
  845.     if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
  846.     {
  847.         m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
  848.         m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
  849.         m_x2 = m_x + m_w;
  850.         m_y2 = m_y + m_h;
  851.         f_oldloc.x = plr->mo->x;
  852.         f_oldloc.y = plr->mo->y;
  853.  
  854.         //  m_x = FTOM(MTOF(plr->mo->x - m_w/2));
  855.         //  m_y = FTOM(MTOF(plr->mo->y - m_h/2));
  856.         //  m_x = plr->mo->x - m_w/2;
  857.         //  m_y = plr->mo->y - m_h/2;
  858.  
  859.     }
  860.  
  861. }
  862.  
  863. //
  864. //
  865. //
  866. void AM_updateLightLev(void)
  867. {
  868.     static nexttic = 0;
  869.     //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
  870.     static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
  871.     static int litelevelscnt = 0;
  872.    
  873.     // Change light level
  874.     if (amclock>nexttic)
  875.     {
  876.         lightlev = litelevels[litelevelscnt++];
  877.         if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
  878.         nexttic = amclock + 6 - (amclock % 6);
  879.     }
  880.  
  881. }
  882.  
  883.  
  884. //
  885. // Updates on Game Tick
  886. //
  887. void AM_Ticker (void)
  888. {
  889.  
  890.     if (!automapactive)
  891.         return;
  892.  
  893.     amclock++;
  894.  
  895.     if (followplayer)
  896.         AM_doFollowPlayer();
  897.  
  898.     // Change the zoom if necessary
  899.     if (ftom_zoommul != FRACUNIT)
  900.         AM_changeWindowScale();
  901.  
  902.     // Change x,y location
  903.     if (m_paninc.x || m_paninc.y)
  904.         AM_changeWindowLoc();
  905.  
  906.     // Update light level
  907.     // AM_updateLightLev();
  908.  
  909. }
  910.  
  911.  
  912. //
  913. // Clear automap frame buffer.
  914. //
  915. void AM_clearFB(int color)
  916. {
  917.     memset(fb, color, f_w*f_h);
  918. }
  919.  
  920.  
  921. //
  922. // Automap clipping of lines.
  923. //
  924. // Based on Cohen-Sutherland clipping algorithm but with a slightly
  925. // faster reject and precalculated slopes.  If the speed is needed,
  926. // use a hash algorithm to handle  the common cases.
  927. //
  928. boolean
  929. AM_clipMline
  930. ( mline_t*      ml,
  931.   fline_t*      fl )
  932. {
  933.     enum
  934.     {
  935.         LEFT    =1,
  936.         RIGHT   =2,
  937.         BOTTOM  =4,
  938.         TOP     =8
  939.     };
  940.     
  941.     register    outcode1 = 0;
  942.     register    outcode2 = 0;
  943.     register    outside;
  944.     
  945.     fpoint_t    tmp;
  946.     int         dx;
  947.     int         dy;
  948.  
  949.     
  950. #define DOOUTCODE(oc, mx, my) \
  951.     (oc) = 0; \
  952.     if ((my) < 0) (oc) |= TOP; \
  953.     else if ((my) >= f_h) (oc) |= BOTTOM; \
  954.     if ((mx) < 0) (oc) |= LEFT; \
  955.     else if ((mx) >= f_w) (oc) |= RIGHT;
  956.  
  957.     
  958.     // do trivial rejects and outcodes
  959.     if (ml->a.y > m_y2)
  960.         outcode1 = TOP;
  961.     else if (ml->a.y < m_y)
  962.         outcode1 = BOTTOM;
  963.  
  964.     if (ml->b.y > m_y2)
  965.         outcode2 = TOP;
  966.     else if (ml->b.y < m_y)
  967.         outcode2 = BOTTOM;
  968.     
  969.     if (outcode1 & outcode2)
  970.         return false; // trivially outside
  971.  
  972.     if (ml->a.x < m_x)
  973.         outcode1 |= LEFT;
  974.     else if (ml->a.x > m_x2)
  975.         outcode1 |= RIGHT;
  976.     
  977.     if (ml->b.x < m_x)
  978.         outcode2 |= LEFT;
  979.     else if (ml->b.x > m_x2)
  980.         outcode2 |= RIGHT;
  981.     
  982.     if (outcode1 & outcode2)
  983.         return false; // trivially outside
  984.  
  985.     // transform to frame-buffer coordinates.
  986.     fl->a.x = CXMTOF(ml->a.x);
  987.     fl->a.y = CYMTOF(ml->a.y);
  988.     fl->b.x = CXMTOF(ml->b.x);
  989.     fl->b.y = CYMTOF(ml->b.y);
  990.  
  991.     DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  992.     DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  993.  
  994.     if (outcode1 & outcode2)
  995.         return false;
  996.  
  997.     while (outcode1 | outcode2)
  998.     {
  999.         // may be partially inside box
  1000.         // find an outside point
  1001.         if (outcode1)
  1002.             outside = outcode1;
  1003.         else
  1004.             outside = outcode2;
  1005.         
  1006.         // clip to each side
  1007.         if (outside & TOP)
  1008.         {
  1009.             dy = fl->a.y - fl->b.y;
  1010.             dx = fl->b.x - fl->a.x;
  1011.             tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
  1012.             tmp.y = 0;
  1013.         }
  1014.         else if (outside & BOTTOM)
  1015.         {
  1016.             dy = fl->a.y - fl->b.y;
  1017.             dx = fl->b.x - fl->a.x;
  1018.             tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
  1019.             tmp.y = f_h-1;
  1020.         }
  1021.         else if (outside & RIGHT)
  1022.         {
  1023.             dy = fl->b.y - fl->a.y;
  1024.             dx = fl->b.x - fl->a.x;
  1025.             tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
  1026.             tmp.x = f_w-1;
  1027.         }
  1028.         else if (outside & LEFT)
  1029.         {
  1030.             dy = fl->b.y - fl->a.y;
  1031.             dx = fl->b.x - fl->a.x;
  1032.             tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
  1033.             tmp.x = 0;
  1034.         }
  1035.  
  1036.         if (outside == outcode1)
  1037.         {
  1038.             fl->a = tmp;
  1039.             DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  1040.         }
  1041.         else
  1042.         {
  1043.             fl->b = tmp;
  1044.             DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  1045.         }
  1046.         
  1047.         if (outcode1 & outcode2)
  1048.             return false; // trivially outside
  1049.     }
  1050.  
  1051.     return true;
  1052. }
  1053. #undef DOOUTCODE
  1054.  
  1055.  
  1056. //
  1057. // Classic Bresenham w/ whatever optimizations needed for speed
  1058. //
  1059. void
  1060. AM_drawFline
  1061. ( fline_t*      fl,
  1062.   int           color )
  1063. {
  1064.     register int x;
  1065.     register int y;
  1066.     register int dx;
  1067.     register int dy;
  1068.     register int sx;
  1069.     register int sy;
  1070.     register int ax;
  1071.     register int ay;
  1072.     register int d;
  1073. /*    
  1074.     static fuck = 0;
  1075.  
  1076.     // For debugging only
  1077.  
  1078.     if (      fl->a.x < 0 || fl->a.x >= f_w
  1079.            || fl->a.y < 0 || fl->a.y >= f_h
  1080.            || fl->b.x < 0 || fl->b.x >= f_w
  1081.            || fl->b.y < 0 || fl->b.y >= f_h)
  1082.     {
  1083.         fprintf(stderr, "fuck %d \r", fuck++);
  1084.         return;
  1085.     }
  1086. */
  1087.  
  1088. #define PUTDOT(xx,yy,cc) fb[(yy+wy)*finit_width+(xx+wx)]=(cc)
  1089.  
  1090.     dx = fl->b.x - fl->a.x;
  1091.     ax = 2 * (dx<0 ? -dx : dx);
  1092.     sx = dx<0 ? -1 : 1;
  1093.  
  1094.     dy = fl->b.y - fl->a.y;
  1095.     ay = 2 * (dy<0 ? -dy : dy);
  1096.     sy = dy<0 ? -1 : 1;
  1097.  
  1098.     x = fl->a.x;
  1099.     y = fl->a.y;
  1100.  
  1101.     if (ax > ay)
  1102.     {
  1103.         d = ay - ax/2;
  1104.         while (1)
  1105.         {
  1106.             PUTDOT(x,y,color);
  1107.             if (x == fl->b.x) return;
  1108.             if (d>=0)
  1109.             {
  1110.                 y += sy;
  1111.                 d -= ax;
  1112.             }
  1113.             x += sx;
  1114.             d += ay;
  1115.         }
  1116.     }
  1117.     else
  1118.     {
  1119.         d = ax - ay/2;
  1120.         while (1)
  1121.         {
  1122.             PUTDOT(x, y, color);
  1123.             if (y == fl->b.y) return;
  1124.             if (d >= 0)
  1125.             {
  1126.                 x += sx;
  1127.                 d -= ay;
  1128.             }
  1129.             y += sy;
  1130.             d += ax;
  1131.         }
  1132.     }
  1133. }
  1134.  
  1135.  
  1136.  
  1137. //
  1138. // Clip lines, draw visible part sof lines.
  1139. //
  1140. void
  1141. AM_drawMline
  1142. ( mline_t*      ml,
  1143.   int           color )
  1144. {
  1145.     static fline_t fl;
  1146.     mline_t     l;
  1147.  
  1148.     /* Rotate Map Patch - CDE 98' */
  1149.     if(rotatemap) {
  1150.         l.a.x = ml->a.x-plr->mo->x;
  1151.         l.a.y = ml->a.y-plr->mo->y;
  1152.         l.b.x = ml->b.x-plr->mo->x;
  1153.         l.b.y = ml->b.y-plr->mo->y;
  1154.  
  1155.         AM_rotate(&l.a.x, &l.a.y, ANG90-plr->mo->angle);
  1156.         AM_rotate(&l.b.x, &l.b.y, ANG90-plr->mo->angle);
  1157.  
  1158.         l.a.x += plr->mo->x;
  1159.         l.a.y += plr->mo->y;
  1160.         l.b.x += plr->mo->x;
  1161.         l.b.y += plr->mo->y;
  1162.  
  1163.         if (AM_clipMline(&l, &fl))
  1164.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1165.     } else {
  1166.         if (AM_clipMline(ml, &fl))
  1167.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1168.     }
  1169. }
  1170.  
  1171.  
  1172.  
  1173. //
  1174. // Draws flat (floor/ceiling tile) aligned grid lines.
  1175. //
  1176. void AM_drawGrid(int color)
  1177. {
  1178.     fixed_t x, y;
  1179.     fixed_t start, end;
  1180.     mline_t ml;
  1181.  
  1182.     // Figure out start of vertical gridlines
  1183.     start = m_x;
  1184.     if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
  1185.         start += (MAPBLOCKUNITS<<FRACBITS)
  1186.             - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
  1187.     end = m_x + m_w;
  1188.  
  1189.     // draw vertical gridlines
  1190.     ml.a.y = m_y;
  1191.     ml.b.y = m_y+m_h;
  1192.     for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
  1193.     {
  1194.         ml.a.x = x;
  1195.         ml.b.x = x;
  1196.         AM_drawMline(&ml, color);
  1197.     }
  1198.  
  1199.     // Figure out start of horizontal gridlines
  1200.     start = m_y;
  1201.     if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
  1202.         start += (MAPBLOCKUNITS<<FRACBITS)
  1203.             - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
  1204.     end = m_y + m_h;
  1205.  
  1206.     // draw horizontal gridlines
  1207.     ml.a.x = m_x;
  1208.     ml.b.x = m_x + m_w;
  1209.     for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
  1210.     {
  1211.         ml.a.y = y;
  1212.         ml.b.y = y;
  1213.         AM_drawMline(&ml, color);
  1214.     }
  1215.  
  1216. }
  1217.  
  1218. //
  1219. // Determines visible lines, draws them.
  1220. // This is LineDef based, not LineSeg based.
  1221. //
  1222. void AM_drawWalls(void)
  1223. {
  1224.     int i;
  1225.     static mline_t l;
  1226.  
  1227.     for (i=0;i<numlines;i++)
  1228.     {
  1229.         l.a.x = lines[i].v1->x;
  1230.         l.a.y = lines[i].v1->y;
  1231.         l.b.x = lines[i].v2->x;
  1232.         l.b.y = lines[i].v2->y;
  1233.         if (cheating || (lines[i].flags & ML_MAPPED))
  1234.         {
  1235.             if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
  1236.                 continue;
  1237.             if (!lines[i].backsector)
  1238.             {
  1239.                 AM_drawMline(&l, WALLCOLORS+lightlev);
  1240.             }
  1241.             else
  1242.             {
  1243.                 if (lines[i].special == 39)
  1244.                 { // teleporters
  1245.                     AM_drawMline(&l, WALLCOLORS+WALLRANGE/2);
  1246.                 }
  1247.                 else if (lines[i].flags & ML_SECRET) // secret door
  1248.                 {
  1249.                     if (cheating) AM_drawMline(&l, SECRETWALLCOLORS + lightlev);
  1250.                     else AM_drawMline(&l, WALLCOLORS+lightlev);
  1251.                 }
  1252.                 else if (lines[i].backsector->floorheight
  1253.                            != lines[i].frontsector->floorheight) {
  1254.                     AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
  1255.                 }
  1256.                 else if (lines[i].backsector->ceilingheight
  1257.                            != lines[i].frontsector->ceilingheight) {
  1258.                     AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
  1259.                 }
  1260.                 else if (cheating) {
  1261.                     AM_drawMline(&l, TSWALLCOLORS+lightlev);
  1262.                 }
  1263.             }
  1264.         }
  1265.         else if (plr->powers[pw_allmap])
  1266.         {
  1267.             if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
  1268.         }
  1269.     }
  1270. }
  1271.  
  1272. void
  1273. AM_drawLineCharacter
  1274. ( mline_t*      lineguy,
  1275.   int           lineguylines,
  1276.   fixed_t       scale,
  1277.   angle_t       angle,
  1278.   int           color,
  1279.   fixed_t       x,
  1280.   fixed_t       y )
  1281. {
  1282.     int         i;
  1283.     mline_t     l;
  1284.  
  1285.     for (i=0;i<lineguylines;i++)
  1286.     {
  1287.         l.a.x = lineguy[i].a.x;
  1288.         l.a.y = lineguy[i].a.y;
  1289.  
  1290.         if (scale)
  1291.         {
  1292.             l.a.x = FixedMul(scale, l.a.x);
  1293.             l.a.y = FixedMul(scale, l.a.y);
  1294.         }
  1295.  
  1296.         if (angle)
  1297.             AM_rotate(&l.a.x, &l.a.y, angle);
  1298.  
  1299.         l.a.x += x;
  1300.         l.a.y += y;
  1301.  
  1302.         l.b.x = lineguy[i].b.x;
  1303.         l.b.y = lineguy[i].b.y;
  1304.  
  1305.         if (scale)
  1306.         {
  1307.             l.b.x = FixedMul(scale, l.b.x);
  1308.             l.b.y = FixedMul(scale, l.b.y);
  1309.         }
  1310.  
  1311.         if (angle)
  1312.             AM_rotate(&l.b.x, &l.b.y, angle);
  1313.         
  1314.         l.b.x += x;
  1315.         l.b.y += y;
  1316.  
  1317.         AM_drawMline(&l, color);
  1318.     }
  1319. }
  1320.  
  1321. void AM_drawPlayers(void)
  1322. {
  1323.     int         i;
  1324.     player_t*   p;
  1325.     static int  their_colors[] = { GREENS, GRAYS, BROWNS, REDS };
  1326.     int         their_color = -1;
  1327.     int         color;
  1328.  
  1329.     if (!netgame)
  1330.     {
  1331.         if (cheating)
  1332.             AM_drawLineCharacter
  1333.                 (cheat_player_arrow, NUMCHEATPLYRLINES, 0,
  1334.                  plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
  1335.         else
  1336.             AM_drawLineCharacter
  1337.                 (player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
  1338.                  WHITE, plr->mo->x, plr->mo->y);
  1339.         return;
  1340.     }
  1341.  
  1342.     for (i=0;i<MAXPLAYERS;i++)
  1343.     {
  1344.         their_color++;
  1345.         p = &players[i];
  1346.  
  1347.         if ( (deathmatch && !singledemo) && p != plr)
  1348.             continue;
  1349.  
  1350.         if (!playeringame[i])
  1351.             continue;
  1352.  
  1353.         if (p->powers[pw_invisibility])
  1354.             color = 246; // *close* to black
  1355.         else
  1356.             color = their_colors[their_color];
  1357.         
  1358.         AM_drawLineCharacter
  1359.             (player_arrow, NUMPLYRLINES, 0, p->mo->angle,
  1360.              color, p->mo->x, p->mo->y);
  1361.     }
  1362.  
  1363. }
  1364.  
  1365. void
  1366. AM_drawThings
  1367. ( int   colors,
  1368.   int   colorrange)
  1369. {
  1370.     int         i;
  1371.     mobj_t*     t;
  1372.  
  1373.     for (i=0;i<numsectors;i++)
  1374.     {
  1375.         t = sectors[i].thinglist;
  1376.         while (t)
  1377.         {
  1378.             AM_drawLineCharacter
  1379.                 (thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
  1380.                  16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
  1381.             t = t->snext;
  1382.         }
  1383.     }
  1384. }
  1385.  
  1386. void AM_drawMarks(void)
  1387. {
  1388.     int i, fx, fy, w, h;
  1389.     fixed_t x,y;
  1390.  
  1391.  
  1392.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  1393.     {
  1394.         if (markpoints[i].x != -1)
  1395.         {
  1396.             //      w = SWAPSHORT(marknums[i]->width);
  1397.             //      h = SWAPSHORT(marknums[i]->height);
  1398.             w = 5; // because something's wrong with the wad, i guess
  1399.             h = 6; // because something's wrong with the wad, i guess
  1400.  
  1401.             /* CDE'98 Rotate Map Patch - Now rotate marks :) */
  1402.             if(rotatemap)
  1403.             {
  1404.                 x=markpoints[i].x-plr->mo->x;
  1405.                 y=markpoints[i].y-plr->mo->y;
  1406.                 AM_rotate(&x, &y, ANG90-plr->mo->angle);
  1407.                 x += plr->mo->x;
  1408.                 y += plr->mo->y;
  1409.                 fx = CXMTOF(x);
  1410.                 fy = CYMTOF(y);
  1411.             } else {
  1412.                 fx = CXMTOF(markpoints[i].x);
  1413.                 fy = CYMTOF(markpoints[i].y);
  1414.             }
  1415.  
  1416.             if (fx >= f_x  && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
  1417.                 V_DrawPatch(fx+wx, fy+wy, FB, marknums[i]);
  1418.         }
  1419.     }
  1420. }
  1421.  
  1422. void AM_drawCrosshair(int color)
  1423. {
  1424.     /* CDE'98 - Crosshair on the view center whatever size/mode ! */
  1425.  
  1426.  
  1427.     fb[((viewwidth+2*viewwindowx)*(viewheight+2*viewwindowy+1))/2] = color; // single point for now
  1428. }
  1429.  
  1430. void AM_Drawer (void)
  1431. {
  1432.     if (!automapactive) return;
  1433.  
  1434.     /* Map On HeadUp Patch - CDE 98' */
  1435.     if(!maponhu)
  1436.         AM_clearFB(BACKGROUND);
  1437.  
  1438.     if (grid)
  1439.         AM_drawGrid(GRIDCOLORS);
  1440.     AM_drawWalls();
  1441.     AM_drawPlayers();
  1442.     if (cheating==2)
  1443.         AM_drawThings(THINGCOLORS, THINGRANGE);
  1444.     AM_drawCrosshair(XHAIRCOLORS);
  1445.  
  1446.     AM_drawMarks();
  1447.  
  1448.     V_MarkRect(f_x, f_y, f_w, f_h);
  1449.  
  1450. }
  1451.